<template>
  <div class="page-content" style="padding-top: 0px; !important">
    <iframe
      :src="`/pdfjs/web/viewer.html?file=${path}`"
      style="border:0px !important;margin-top: 2px;"
      width="100%"
      height="100%"
    ></iframe>
  </div>
</template>

<script>
//https://hub.fastgit.org/DLTech21/ofd.js
import { parseOfdDocument, renderOfd } from "ofd.js";
export default {
  data() {
    return {
      path: "",
    };
  },
  methods: {
    getPath() {
      let path = `http://${window.location.host}${process.env.VUE_APP_BASE_API}/attachment/open?attachmentId=${this.$attrs.attachmentId}`;
      //return `http://${window.location.host}${process.env.VUE_APP_BASE_API}/attachment/open?attachmentId=${this.$attrs.attachmentId}`;
      return encodeURIComponent(path);
    },
  },
  created() {
    parseOfdDocument({
      ofd: this.getPath(),
      success(res) {
        //输出ofd每页的div
        const divs = renderOfd(screenWidth, res);
        //获取签章div的信息, 具体看demo
        for (let ele of document.getElementsByName("seal_img_div")) {
          this.addEventOnSealDiv(
            ele,
            JSON.parse(ele.dataset.sesSignature),
            JSON.parse(ele.dataset.signedInfo)
          );
        }
      },
      fail(error) {
        console.log(error);
      },
    });
  },
};
</script>

<style scoped>
</style>
